package com.huanlis.nodes.action;

import com.huanlis.core.Action;
import com.huanlis.core.ActionRegistry;
import com.huanlis.core.util.ActionException;
import com.huanlis.nodes.domain.OriginalDataDomain;
import com.huanlis.nodes.domain.ResultDomain;

public class CalculateAction implements Action<OriginalDataDomain, ResultDomain> {

    @Override
    public void register(ActionRegistry actionRegistry) {
        actionRegistry.register("calculate", CalculateAction.class.getCanonicalName(), this);
    }

    @Override
    public ResultDomain execute(OriginalDataDomain dataDomain) throws ActionException {
        ResultDomain resultDomain = new ResultDomain();
        resultDomain.setResult(dataDomain.getAmount() * dataDomain.getPrice());
        return resultDomain;
    }
}
